< previous page page_653 next page >

Page 653
If you need to perform an operation to update the customer ID values in several tables and you also need to update several queries to match new search criteria, you should use database-level locking.
Take a look at a Visual Basic project to see how database-level locking works. Load Visual Basic and open a new project. Add a data control to the form. Set its DataBaseName property to C:\TYSDBVB5\SOURCE\DATA\MULTIUSE.MDB and its Exclusive property to True. Save the form as MULTIUS1.FRM and the project as MULTIUS1.VBP. Now create an executable version of the project by choosing File | Make MULTIUS1.EXE from the Visual Basic main menu. Use MULTIUS1.EXE as the name of the executable file.
Now run the executable file. It loads and displays the data control. Run a second instance of the executable file. This is an attempt to run a copy of the same program. Because this second copy attempts to open the same database for exclusive use, you see an error message when the second program starts (see Figure 17.1).
0653-01.jpg
Figure 17.1.
Attempting to open a locked database.
Notice that the second program continues after the error occurs, even though the database is not opened. You can check for the error when you first load the project by adding the following code to the Error event of the data control:
Private Sub Data1_Error(DataErr As Integer, Response As Integer)
    If Err <> 0 Then
        MsgBox Error$(Err)+Chr(13)+"Exiting Program", vbCritical, "Data1_Error"
        Unload Me
    End If
End Sub

 
< previous page page_653 next page >

If you like this book, buy it!